Skip to content

fix: validate projection engineVersion and V2 trackEmittedStreams combo#390

Merged
w1am merged 3 commits intotrunkfrom
validate-projection-engine-version
May 6, 2026
Merged

fix: validate projection engineVersion and V2 trackEmittedStreams combo#390
w1am merged 3 commits intotrunkfrom
validate-projection-engine-version

Conversation

@w1am
Copy link
Copy Markdown
Contributor

@w1am w1am commented May 6, 2026

Follow-up to #389.

Summary

  • Reject engineVersion values outside 0/1/2 in CreateProjectionOptions.engineVersion.
  • Reject engineVersion == 2 && trackEmittedStreams in CreateProjection.execute() before building the request.

Callers now get an IllegalArgumentException locally instead of a server-side error for documented-invalid inputs.

Reject engineVersion values outside the documented set (0/1/2) and the
V2 + trackEmittedStreams combination before sending the request.
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Validate projection engineVersion and V2 trackEmittedStreams combination

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Validate engineVersion parameter accepts only 0, 1, or 2
• Reject invalid engineVersion == 2 && trackEmittedStreams combination
• Throw IllegalArgumentException locally instead of server-side error
• Improve error messages for invalid projection configurations
Diagram
flowchart LR
  A["CreateProjectionOptions.engineVersion"] -->|validates value| B["0, 1, or 2 only"]
  B -->|throws| C["IllegalArgumentException"]
  D["CreateProjection.execute"] -->|checks| E["engineVersion == 2 && trackEmittedStreams"]
  E -->|throws| C
  C -->|local validation| F["Prevents server-side error"]
Loading

Grey Divider

File Changes

1. src/main/java/io/kurrent/dbclient/CreateProjectionOptions.java 🐞 Bug fix +6/-0

Add engineVersion parameter validation

• Added validation in engineVersion() method to reject values outside 0, 1, 2 range
• Throws IllegalArgumentException with descriptive message for invalid values
• Updated JavaDoc to document the exception behavior

src/main/java/io/kurrent/dbclient/CreateProjectionOptions.java


2. src/main/java/io/kurrent/dbclient/CreateProjection.java 🐞 Bug fix +5/-0

Validate V2 engine and trackEmittedStreams incompatibility

• Added validation in execute() method to reject engineVersion == 2 && trackEmittedStreams
 combination
• Throws IllegalArgumentException before sending request to server
• Prevents invalid V2 engine configuration from reaching the server

src/main/java/io/kurrent/dbclient/CreateProjection.java


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented May 6, 2026

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Sync throw bypasses future ✓ Resolved 🐞 Bug ☼ Reliability
Description
CreateProjection.execute() throws IllegalArgumentException before returning a CompletableFuture when
engineVersion==2 and trackEmittedStreams==true, so KurrentDBProjectionManagementClient.create(...)
can fail synchronously instead of completing the future exceptionally. This breaks common usage
patterns that handle failures via future completion (e.g., catching ExecutionException from .get()).
Code

src/main/java/io/kurrent/dbclient/CreateProjection.java[R32-35]

+        if (engineVersion == 2 && trackEmittedStreams) {
+            throw new IllegalArgumentException(
+                    "trackEmittedStreams is not supported when engineVersion is 2 (V2)");
+        }
Evidence
The new precondition throws before any CompletableFuture is created/returned, and the public
projection management client simply returns execute() directly—so the exception escapes
synchronously at the call site. Existing sample usage patterns show callers generally expecting
failures to surface through the future (ExecutionException on .get()).

src/main/java/io/kurrent/dbclient/CreateProjection.java[30-36]
src/main/java/io/kurrent/dbclient/KurrentDBProjectionManagementClient.java[74-79]
src/test/java/io/kurrent/dbclient/samples/projection_management/ProjectionManagement.java[59-66]
src/test/java/io/kurrent/dbclient/samples/projection_management/ProjectionManagement.java[155-176]
README.md[19-20]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`CreateProjection.execute()` throws `IllegalArgumentException` synchronously for the invalid combination `engineVersion == 2 && trackEmittedStreams == true`. Since the public API returns `CompletableFuture`, callers commonly expect failures to arrive via exceptional completion rather than a synchronous throw.

### Issue Context
The project supports Java 8+, so prefer a Java-8-compatible way to create a failed future (i.e., `new CompletableFuture<>()` + `completeExceptionally(...)`).

### Fix Focus Areas
- src/main/java/io/kurrent/dbclient/CreateProjection.java[30-36]

### Suggested fix
Replace the synchronous `throw` with returning an exceptionally-completed `CompletableFuture` (or move the validation into the options setters while still ensuring the public `create(...)` method does not throw unexpectedly). For Java 8 compatibility:
- Create `CompletableFuture<Projectionmanagement.CreateResp>` (or raw `CompletableFuture` consistent with the current signature)
- `completeExceptionally(new IllegalArgumentException(...))`
- `return failed;`

Optionally, document this behavior in the public client/create Javadocs if you decide to keep synchronous throws.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@w1am w1am self-assigned this May 6, 2026
w1am added 2 commits May 6, 2026 12:45
Match how server-side failures of the same condition surface; keep the
public CompletableFuture API free of synchronous throws.
@w1am w1am merged commit db428f1 into trunk May 6, 2026
42 checks passed
@w1am w1am deleted the validate-projection-engine-version branch May 6, 2026 08:57
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@w1am 👉 Created pull request targeting release/v1.2: #391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant